package com.example.flshtarvel.mapper;

import com.example.flshtarvel.entity.Article;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ArticleMapper {

    //通过信息id获取信息
    @Select("select * from article_type,article where article.article_type_id = article_type.article_type_id and article.article_id=#{articleId}")
    public Article selectArticleById(String articleId);

    @Select("select * from article_type,article where article.article_type_id=article_type.article_type_id and article_type.article_type_name=#{articleTypeName} limit #{offset},#{size}")
    public List<Article> selectAllArticleByArticleTypeName(String articleTypeName, int offset, int size);
    @Select("select * from article_type,article where article.article_type_id=article_type.article_type_id and article_type.article_type_Id=#{articleTypeId} limit #{offset},#{size}")
    public List<Article> selectAllArticleByArticleTypeId(String articleTypeId, int offset, int size);

    //通过信息名称搜索信息(模糊查询)
    @Select("select * from article_type,article where article.article_type_id=article_type.article_type_id and article.article_type_id=#{articleTypeId} and article.article_name like #{likeSql}")
    public List<Article> selectArticleByName(String articleTypeId, String likeSql);

    @Select("select * from article_type,article where article.article_type_id=article_type.article_type_id and article.article_type_id=#{articleTypeId} and article.article_name=#{articleName}")
    public Article getArticeByName(String articleTypeId, String articleName);

    @Insert("insert into article(article_type_id,article_id,mes_type_id,article_name,introduction,traffic,phone,address,tips,money,open,net_facility,trafic_facility,trafic_service,reception_service,food_service,live_time,leave_time,chirdren,breakfast,pet) values(#{articleTypeId},#{articleId},'1',#{articleName},#{introduction},#{traffic},#{phone},#{address},#{tips},#{money},#{open},#{netFacility},#{traficFacility},#{traficService},#{receptionService},#{foodService},#{liveTime},#{leaveTime},#{chirdren},#{breakfast},#{pet})")
    public int insertArticle(Article article);

    @Update("update article set article_name=#{articleName},introduction=#{introduction},traffic=#{traffic},phone=#{phone},address=#{address},tips=#{tips},money=#{money},open=#{open},net_facility=#{netFacility},trafic_facility=#{traficFacility},trafic_service=#{traficService},reception_service=#{receptionService},food_service=#{foodService},live_time=#{liveTime},leave_time=#{leaveTime},chirdren=#{chirdren},breakfast=#{breakfast},pet=#{pet} where article_id=#{articleId}")
    public int updateArticle(Article article);

    @Delete("delete from article where article_id=#{articleId}")
    public int deleteArticle(String articleId);

    @Select("select count(*) from article,article_type where article.article_type_id=article_type.article_type_id and article_type.article_type_name=#{articleTypeName}")
    public int selectArticleCountByArticleTypeName(String articleTypeName);

    @Select("select count(*) from article,article_type where article.article_type_id=article_type.article_type_id and article_type.article_type_id=#{articleTypeId}")
    public int selectArticleCountByArticleTypeId(String articleTypeId);

    //不分类模糊查询
    @Select("select * from article_type,article where article.article_type_id = article_type.article_type_id and article_name like #{likeSql}")
    public List<Article> selectAllArticleByName(String likeSql);
}
